// Copyright (c) 2022 Presto Labs Pte. Ltd.
// Author: hyuan

#pragma once

#include <cstdio>
#include <memory>
#include <set>
#include <string>

#include <rapidjson/document.h>

#include "coin2/exchange/base/order/order.h"
#include "coin2/exchange/coincheck/api_util/rate_tracker.h"
#include "coin2/exchange/coincheck/symbology/product.h"

namespace coin2::exchange::coincheck::order_v1 {

class CoincheckParser : public base::order::BaseParser {
 public:
  using RateLimitInfo = coin2::exchange::coincheck::api_util::RateLimitInfo;

 public:
  const ParseResult& ParseRawMessage(const RawMessage& msg) override;
  AccountBalance ParseBalance(const JsonValue& doc) override;
  bool ParseRawBalance(const JsonValue& doc, RawBalanceMap* raw_balance_map);

 private:
  void ParseRestAccountBalance();
  void ParseRestOpenOrderInfoList();
  void ParseRestDoneOrderInfoList();
  void ParseRestFillOrderInfoList();
  void ParseSubmitResponse();
  void ParseCancelResponse();
  void ParseWsMessage();

  int32_t ParseErrorMessage(const std::shared_ptr<AsioHttpContext>& http_context);

 private:
  RateLimitInfo enable_time_{0};
};

}  // namespace coin2::exchange::coincheck::order_v1
